﻿using ERPEF;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class bs_clientService : bs_clientIService
    {

        private readonly MyDbContext myDbContext;
        public bs_clientService(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        //查询 
        public async Task<List<bs_client>> Query() 
        {
            return await myDbContext.bs_Client.Where(c=>c.IsDeleted == false).ToListAsync();
        }
        //添加
        public async Task<int> Add(bs_client bs_client)
        {
            Console.WriteLine("------Add------>"+bs_client);
            myDbContext.bs_Client.Add(bs_client);
            return await myDbContext.SaveChangesAsync();
        }

        //逻辑删除
        public async Task<int> Delete(int client_id)
        {
            var del=myDbContext.bs_Client.Find(client_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await myDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }
        //修改
        public async Task<int> Update(bs_client bsClient)
        {
            myDbContext.bs_Client.Update(bsClient);
            return await myDbContext.SaveChangesAsync();
        }
    }
}
